package com.study.api;

import com.study.anno.Idempotence;
import com.study.anno.SignParamAnnotation;
import com.study.api.IdController.DataDTO.Avo;
import io.swagger.annotations.Api;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhuzi
 * 2024/6/27 下午3:57
 */
@Api(tags = "幂等性测试")
@Slf4j
@RestController
@RequestMapping("id")
public class IdController {

    @Idempotence
    @GetMapping("a")
    public String id(String type, String name, HttpServletRequest request) {
        System.out.println(request.getRemoteAddr());

        return type + name;
    }

    @Idempotence
    @PostMapping("b")
    public String idb(String type, String name, HttpServletRequest request) {
        System.out.println(request.getRemoteAddr());
        return type + name;
    }

    @Idempotence
    @PostMapping("c")
    public String c(@RequestBody @SignParamAnnotation Avo avo, HttpServletRequest request) {
        return avo.toString();
    }


    @Idempotence
    @GetMapping("/header")
    public String webSite(@RequestHeader("webSite") String webSite) {
        return "The webSite is " + webSite;
    }

    interface DataDTO {
        @Data
        @Accessors(chain = true)
        class Avo {
            private String type;
            private String name;
        }
    }

}
